import 'package:changxindianzishangwu/cache/local_cache.dart';
import 'package:changxindianzishangwu/http/base/ec_base_request.dart';
import 'package:changxindianzishangwu/http/request/collect_delete_request.dart';
import 'package:changxindianzishangwu/http/request/collect_list_data_request.dart';
import 'package:changxindianzishangwu/http/request/collect_query_request.dart';
import 'package:changxindianzishangwu/http/request/collect_request.dart';
import 'package:changxindianzishangwu/http/request/collect_update_note_request.dart';
import 'package:changxindianzishangwu/http/zd_net.dart';
import 'package:changxindianzishangwu/model/collect_list_model.dart';
import 'package:changxindianzishangwu/util/toast.dart';

class CollectDao {
  static addCollect(String msgId, String type, String url,
      {String roomJid, String emoji}) async {
    EcBaseRequest request = CollectRequest();
    request
        .add("access_token", getAppLoginToken())
        .add("msgId", msgId)
        .add("type", type)
        .add("url", url)
        .add("roomJid", roomJid)
        .add("emoji", emoji);
    var result = await ZdNet.getInstance().send(request);
    print(result);
    if (result['resultCode'] == 0) {
      showToast(result['resultMsg']);
    } else if (result['resultCode'] == 1) {
      showToast("成功！");
    }
    return result;
  }

  static getCollectData(int type, int page) async {
    print('--------AAA');
    EcBaseRequest request = CollectListDataRequest();
    request
        .add("access_token", getAppLoginToken())
        .add("type", type)
        .add("userId", getUserInfo().userId)
        .add("pageIndex", page)
        .add("pageSize", 10);
    var result = await ZdNet.getInstance().send(request);
    print(result);
    return CollectListModel.fromJson(result);
  }

  static collectUpdateNote(String emojiId, String remarks) async {
    EcBaseRequest request = CollectUpdateNoteRequest();
    request
        .add("access_token", getAppLoginToken())
        .add("emojiId", emojiId)
        .add("userId", getUserInfo().userId)
        .add("remarks", remarks);
    var result = await ZdNet.getInstance().send(request);

    return CollectListModel.fromJson(result);
  }

  static Future<int> collectDelete(String emojiId) async {
    EcBaseRequest request = CollectDeleteRequest();
    request
        .add("access_token", getAppLoginToken())
        .add("emojiId", emojiId)
        .add("userId", getUserInfo().userId);
    var result = await ZdNet.getInstance().send(request);

    return result["resultCode"];
  }

  static collectQueryRequest(int pageIndex, String search) async {
    print('--------bbb');

    EcBaseRequest request = CollectQueryRequest();
    request
        .add("access_token", getAppLoginToken())
        .add("userId", getUserInfo().userId)
        .add("pageIndex", pageIndex)
        .add("pageSize", 10)
        .add("search", search);
    var result = await ZdNet.getInstance().send(request);

    return CollectListModel.fromJson(result);
  }
}
